class List2{
    constructor(){
        this.url2 = "http://localhost/project/data/goods2.json";
        this.cont2 = document.querySelector("#cont2");

        this.load2();

        
    }
    load2(){
        ajax({
            url:this.url2
        }).then((res)=>{
            this.res = JSON.parse(res);
            this.display2();
        })
    }
    display2(){
        let str2 = "";
        for(var i=0;i<this.res.length;i++){
            str2 += `<div class="goods" index="${this.res[i].goodsId}">
                        <a href="goodsdetails.html?id=${this.res[i].goodsId}">
                            <img src="${this.res[i].img.largeImg[0]}" alt="">
                            <p class="name">${ this.res[i].name }</p>
                            <div class="youhui">${ this.res[i].youhui }</div>
                            <span>${this.res[i].price}</span>
                        </a>
                        <input type="button" value="加入购物车" class="add">
                    </div>`
        }
        this.cont2.innerHTML = str2;
    }
}

new List2;